{% extends "base.html" %}

{% block title %}消费统计 - 记账系统{% endblock %}

{% block content %}
    <h2>消费统计</h2>
    <form method="post" action="{{ url_for('statistics') }}" class="filter-form">
        <div>
            <label for="year">年份:</label>
            <input type="number" id="year" name="year" value="{{ selected_year }}" required placeholder="例如 2024">
        </div>
        <div>
            <label for="month">月份 (1-12, 留空为全年):</label>
            <input type="number" id="month" name="month" min="1" max="12" value="{{ selected_month }}" placeholder="例如 8">
        </div>
        <div>
            <button type="submit">查询统计</button>
        </div>
    </form>

    <h3>{{ selected_year }}年 {{ selected_month if selected_month else '全年' }} 按大分类统计:</h3>
    {% if stats %}
    <table>
        <thead>
            <tr>
                <th>大分类</th>
                <th>总金额</th>
            </tr>
        </thead>
        <tbody>
        {% for item in stats %}
            <tr>
                <td>{{ item.main_category }}</td>
                <td>{{ "%.2f"|format(item.total) }}</td>
            </tr>
        {% endfor %}
        </tbody>
    </table>
    {% else %}
    <p>该时段无消费数据，或未找到符合条件的统计结果。</p>
    {% endif %}
{% endblock %}
